package inscription
import institutional.Major
import user.Student

class InscriptionMajor {
	final public static int IN_PROGRESS = 0
	final public static int FINISHED = 1
	final public static int CANCELLED = 2
	
	
	int status	
	Date dateOfCreation
	Date lastUpdate
	Major major
	Student student
	
	
	
    static constraints = {
    }
	
	@Override
	public String toString () {
		return "$major: ${this.getStatusInString()}"
	}
	
	public getStatusInString() {
		if (isActive()) return "IN PROGRESS"
		if (isFinished()) return "FINISHED"
		else return "CANCELLED"
	}
	
	public boolean isActive() {
		(status == IN_PROGRESS)
	}
	
	public void setActive () {
		if (!isActive()) {
			status = IN_PROGRESS
			lastUpdate = new Date().time
		}
	}
	
	public boolean isFinished() {
		(status ==  FINISHED)
	}
	
	public void setFinished () {
		if (!isFinished()) {
			status = FINISHED
			lastUpdate = new Date().time
		}
	}
	
	public boolean isCancelled() {
		(status ==  CANCELLED)
	}
	
	public void setCancelled () {
		if (!isCancelled()) {
			status = CANCELLED
			lastUpdate = new Date().time
		}
	}
	
}
